// uni.removeStorageSync('CHAT')
let messageLastList = []
let defaultMessageList = uni.getStorageSync('CHAT')
console.log(defaultMessageList)
if (!defaultMessageList) {
    messageLastList = []
} else {
    for (let key in defaultMessageList) {
        console.log(defaultMessageList[key])
        const len = defaultMessageList[key].msgContent.length - 1
        const info = {
            ...defaultMessageList[key].msgContent[len],
            targetId: key
        }
        messageLastList.push(info)
    }
}
const state = {
    history: [],
    targetId: '',
    messageList: messageLastList.sort((a, b) => b.time - a.time),
		unReadCount: 0
}
const mutations = {
    SET_HISTORY: (state, history) => {
        state.history = history
    },
    SET_TARGET: (state, id) => {
        state.targetId = id
    },
    SET_MESSAGE_LIST: (state, info) => {
        state.messageList = info
    },
		SET_UN_READ_COUNT:(state, count) => {
			state.unReadCount = count
		}
}
const actions = {
    updateHistory({ commit }, history) {
        commit('SET_HISTORY', history)
    },
    updateId({ commit }, id) {
        commit('SET_TARGET', id)
    },
    updateMessage({ commit }, info) {
        commit('SET_MESSAGE_LIST', info)
    },
		updateUnread({ commit }, count) {
			commit('SET_UN_READ_COUNT', count)
		}
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}